# Make the app's "gems" directory a place where gems are loaded from
Gem.clear_paths
Gem.path.unshift(Merb.root / "gems")

# Make the app's "lib" directory a place where ruby files get "require"d from
$LOAD_PATH.unshift(Merb.root / "lib")

# Make debugger halted if exception occurs
# Debugger.post_mortem rescue nil

#____________________DON'T CHANGE THESE SETTINGS____________________
#_____OVERWRITE CONFIGURATION IN OWN CONFIG/ENGINE_CONFIG.RB________
Merb::Config.use do |c|
  c[:environment] = 'development' #development, production, testing
  c[:log_level] = :info #:debug, :info, :warn, :error, :fatal
  c[:port] = 3000
  c[:host_name] = "localhost"
  c[:use_mutex] = false #use of ActiveRecord in multithreaded environment can be dangerous!
  c[:cluster] = 0 #use in production mode for starting a mongrel cluster with X instances
  
  c[:log_file] = "log/#{c[:environment]}.log"
  
  c[:gui_debug] = true #more detailed web interface
  c[:locator_caching] = true
  c[:data_path] = 'data'
  c[:enable_auth] = true #if false, a random username + password is set
  
  c[:session_id_key] = 'session_id'
  c[:session_secret_key] = '4c4936389dc96a7704153d05928a10302d742d78'
  c[:session_store] = 'cookie'
  
  c[:use_reevaluation] = false
end 
require 'config/engine_config' if File.exist?("config/engine_config.rb")
Merb::Config.use do |c|
  c[:root] = "http://#{c[:host_name]}:#{c[:port]}"
end

use_orm :activerecord
use_test :rspec

dependency 'rubygems'
dependency 'merb-assets'
require 'rake'
require 'base64'
require 'uri'
require 'pathname'
require 'atom/collection'
require 'atom/entry'
require 'http_requests'
require 'util/FileGenerator'
require 'util/ArcExprFileGenerator'
require 'util/AutofireFileGenerator'
require 'erb'
require 'xml/xslt'
require 'rexml/document'
require 'net/http'
require 'uri'
require 'csv_logger'
require 'xml_helpers'

### Add your other dependencies here, some examples:
# dependencies "RedCloth", "merb_helpers"
# OR
# dependency "RedCloth", "> 3.0"
# OR
# dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0"

Merb::BootLoader.after_app_loads do
  ### Add dependencies here that must load after the application loads:
  require 'pnml_parser'
  # dependency "magic_admin" # this gem uses the app's model classes
  
  PetrinetObserver.instance
  TransitionObserver.instance
  ArcObserver.instance
  TokenObserver.instance
  
  #Thread.new do
  #  while(true) do
  #    PullPlace.find(:all).each do |place|
  #      Merb.logger.info "Updating PullPlace with id #{place.id}"
  #      place.sync
  #    end
  #    sleep Merb::Config["TRIGGER_PULL_EVERY_XX_SECONDS"]
  #  end
  #end

  $TIMESTAMPS = {}
  
  #overwrites Merbs default-contenttype for html, because engine should always deliver xhtml
  Merb.add_mime_type(:html, :to_html, %w[application/xhtml+xml text/html application/html])
  Merb.add_mime_type(:atom, :to_atom, %w[application/atom+xml]) 
  Merb.add_mime_type(:pnml, :to_pnml, %w[application/pnml+xml])
end
